package com.bitdf.txing.group.feign.impl.product;

import com.bitdf.txing.common.enume.TxCodeEnume;
import com.bitdf.txing.common.to.es.SkuEsModel;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.product.feign.ProductSearchFeignService;
import com.bitdf.txing.search.service.MallProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * @author Lizhiwei
 * @date 2023/9/6 19:27:47
 * 注释：
 */
@Service
@Slf4j
@ConditionalOnProperty(value = "tx.deploy.mode", havingValue = "standalone")
public class ProductSearchFeignServiceImpl implements ProductSearchFeignService {
    @Autowired
    MallProductSaveService productSaveService;
    @Override
    public R productStatusUp(List<SkuEsModel> skuEsModels) {
        boolean b = false;
        try {
            b = productSaveService.productStatusUp(skuEsModels);
        } catch (IOException e) {
            log.error("商品上架错误", e);
            return R.error(TxCodeEnume.PRODUCT_UP_FAILURE_EXCEPTION);
        }
        if (b) {
            log.info("商品成功上架");
            return R.ok();

        } else {
            log.info("商品上架失败");
            return R.error(TxCodeEnume.PRODUCT_UP_FAILURE_EXCEPTION);
        }

    }
}
